@extends('admin.layouts.default')
@section('content')
    <div class="card">
        <div class="card-body">
            <nav class="navbar nav navbar-light bg-light rounded justify-content-between">
                <a class="navbar-link active" href="{{route('admin.user_role.index')}}">用户-角色对照表</a>
                <form class="form-inline" action="{{route('admin.user_role.store')}}" method="post">
                    @csrf
                    {{--前台也可以通过request('sou')函数获取后台request验证的参数--}}
                    <input class="form-control mr-sm-2" type="search" name="sou" value="{{isset($data)?$data:''}}" placeholder="Search" aria-label="Search">
                    <button class="btn btn-outline-secondary my-2 my-sm-0" type="submit">搜索用户</button>
                </form>
            </nav>
        </div>
        <div class="card-body">
            <table class="table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>用户名</th>
                    <th>用户邮箱</th>
                    <th>用户角色</th>
                </tr>
                </thead>
                <tbody>
                @foreach($users as $user)
                    <tr>
                        <td scope="row">{{$user['id']}}</td>
                        <td>{{$user['name']}}</td>
                        <td>{{$user['email']}}</td>
                        <td>
                            @if($user->getRoleNames()->toArray())
                                {{--<td>{{implode($user->getRoleNames()->toArray())}}</td>--}}
                                @foreach($user->getRole() as $role)
                                    <a href="{{route('admin.role.permission',$role)}}" target="_blank">
                                        <span class="badge badge-secondary">{{$role['title']}}</span>
                                    </a>
                                @endforeach
                            @else
                                <span class="badge badge-secondary">无角色</span>
                            @endif
                        </td>
                        <td>
                            <a href="{{route('admin.user_role.edit',$user)}}" class="btn btn-sm btn-primary">编辑用户角色</a>
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>

        </div>
        {{$users->links()}}
    </div>
@endsection
